<div class="mask-box">
  <%= form_for(@check_in, :url => check_in_admin_course_weeks_path, method: :post, remote:true)  do |f|%>
  <div class="mask-head">
    <h4>学员签到</h4>
    <span></span>
  </div>
  <div class="mask-con">
    <div class="mask-marc">
      <ul>
        <li>
          <span>选择学员:</span>
          <input type="" name="check_in[student_id]" id="student_id">
          <div class="single-box">
            <div class="single-downbtn">
              <span>学员列表</span> 
              <em></em>
            </div>
            <div class="single-dropdown">
              <em></em>
              <input type="text" placeholder="搜索">
              <ul>
                <% @students.each do |stu| %>
                  <li data_id="<%= stu.id %>"><%= stu.name %></li>
                <%end%>
              </ul>
            </div>
          </div>
        </li>
        <li>
          <span>选择课程:</span>
          <em><%= @course.course_info.name %></em>
        </li>
        <li>
          <span>课程导师:</span>
          <em><%= @course.course_info.teacher.name %></em>
        </li>
        <li>
          <span>上课教室:</span>
          <em><%= @course.course_info.room.room_name %></em>
        </li>
        <li>
          <span>上课时间:</span>
          <em><%= @course.course_time.strftime("%Y-%m-%d %H:%M") %></em>
        </li>
        <li>
          <span>消费方式:</span>
          <input type="text" name="check_in[pay_way]" id="check_in_pay_way" />
          <div class="list-box student_paying_way">
            <div class="downbtn">
              <span>已购买卡种</span>
              <em></em>
            </div>
            <ul class="dropdown-menu ways">
              <% @pay_ways.each do |pw| %>
                <li data_id="<%= pw %>"><%= pw %></li>
              <% end %>
            </ul>
          </div>
        </li>
      </ul>
    </div>
  </div>
    <%= f.hidden_field :course_id %>
    <%= tag(:input, :type => "hidden", :name =>  request_forgery_protection_token.to_s, :value =>   form_authenticity_token) %> 
  <div ><%= f.submit '确认签到', :class => "mask-confirm" %></div>
  <%end%>
<script type="text/javascript" language="javascript" charset="utf-8">
//<![CDATA[
  
$(".single-downbtn").on("click", function() {
  if ($(this).next(".single-dropdown").hasClass("menuopen")) {
    $(this).next(".single-dropdown").removeClass("menuopen");
  } else {
    $(this).next(".single-dropdown").addClass("menuopen");
    $(this).parent().hover(function() {

    }, function() {
      $(this).children(".single-dropdown").removeClass("menuopen");
    });
    $(".menuopen li").on("click", function() {
      $(this).parent().parent().removeClass("menuopen");
      $(this).parent().parent().parent().find("span").text($(this).text());
      $(this).parent().parent().find("input").val("");
      $(".single-dropdown li").removeClass("mul-hide");
      $("#student_id").val($(this).attr("data_id"));
      stu_id = $(this).attr("data_id");
      $.ajax({
        type:'get', url:"/admin/course_weeks/get_pay_way?student_id=" + stu_id + "&course_info_id=<%= @course.course_info_id %>",
        success: function(data) {
          if (data.error) {
            // console.log("wrong");
          } 
        }
      });
    });
    $(this).next("div").find("input").on('input',function(){ 
      console.log($(this));
      if ($(this).val() != "") {
        console.log($(this).val());
        $(".single-dropdown li").addClass("mul-hide");
        console.log($($(".single-dropdown li:contains(" + $(this).val() + ")")).removeClass("mul-hide"));
      } else {
        $(".single-dropdown li").removeClass("mul-hide");
      }
    })
  }
});
changeDown();
function changeDown() {
 $(".mask-marc .downbtn").on("click", function() {
    if ($(this).next("ul").hasClass("menuopen")) {
      $(this).next("ul").removeClass("menuopen");
    } else {
      $(this).next("ul").addClass("menuopen");
      $(this).parent().hover(function() {

      }, function() {
        $(this).children("ul").removeClass("menuopen");
      });
      $(".mask-marc .menuopen li").on("click", function() {
        $(this).parent().removeClass("menuopen");
        $("#check_in_pay_way").val($(this).attr("data_id"));
        $(this).parent().parent().children("div").children("span").text($(this).text());
        if ($(this).parent().parent().attr("Choice") == "mandatory" || $(this).parent().parent().attr("Choice") == "selected") {
          if ($(this).index() != 0) {
            // if ($(this).parent().parent().hasClass("b-sex")) {
            // 	console.log("aaaaaa");
            // };
            if ($(this).parent().parent().hasClass("spe")) {

              $(this).parent().parent().children("div").children("span").attr("data_id", $(this).attr("data_id"));
            };
            $(this).parent().parent().attr("Choice", "selected");
            $(this).parent().parent().next("b").css({
              "display" : "none"
            })
          } else {
            $(this).parent().parent().attr("Choice", "mandatory");
          }
        };
      })
    }
  });
}
//]]>
</script>
</div>
